/**
 * 
 */
package org.bookie.model;

import java.io.Serializable;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

/**
 * Class modelling a persistable entity. This class is the main class for all
 * persitable entities.
 * 
 * @author Igor Drobiazko
 * 
 */
@MappedSuperclass
public abstract class CommonEntity implements Serializable {
	/** Identifier of the entity */
	@Id
	@GeneratedValue(strategy=GenerationType.AUTO)
	private Long id;

	/**
	 * Get the identifier of the entity
	 */
	public Long getId() {
		return id;
	}

	/**
	 * Set the identifier of the entity
	 * 
	 * @param id
	 *            identifier to set
	 */
	public void setId(Long id) {
		this.id = id;
	}

	@Override
	public boolean equals(Object object) {
		if (object != null && object instanceof CommonEntity && getId() != null
				&& ((CommonEntity) object).getId() != null) {
			return getId().equals(((CommonEntity)object).getId());
		}
		return super.equals(object);
	}

	@Override
	public int hashCode() {
		return String.valueOf(getId()).hashCode();
	}
}
